import matplotlib.pyplot as plt
import numpy as np
from test3 import create_polar_system

# 创建极坐标系
fig, ax = create_polar_system(r_range=(0, 5))

# 生成θ值（避开sinθ=0的点）
theta_values3 = np.linspace(0.01, np.pi - 0.01, 200)

# 经过点(b,π/2)的水平直线的参数
b = 3              

# 计算ρ值：ρ = b / sinθ
rho_values3 = b / np.sin(theta_values3)

# 过滤掉ρ值过大的点
mask = (rho_values3 <= 5) & (rho_values3 >= 0)
theta_values3 = theta_values3[mask]
rho_values3 = rho_values3[mask]

ax.plot(theta_values3, rho_values3, 'g-', linewidth=2, label='平行极轴: ρ sin θ = 3')

# 标记点M(b,π/2) = (3,π/2)
ax.plot(np.pi/2, b, 'go', markersize=8, label='点M(3,π/2)')

# 添加图例和装饰
ax.legend(loc='upper right', bbox_to_anchor=(1.15, 1.15))

ax.text(np.pi/2 + 0.1, b + 0.3, 'M(3,π/2)', fontsize=10, color='green')

plt.tight_layout()
plt.show()